﻿using System;
using System.Collections.Generic;
using System.Linq;
using Yamfinder.Data;
using Yamfinder.Service;

namespace Yamfinder.Web.Models
{
    public class ImportMappingsModel
    {
        public ImportMappingsModel() { }

        public ImportMappingsModel(Guid id, IEnumerable<AnalysedImportColumn> mappings, IEnumerable<DataDictonaryEntry> existingFields)
        {
            Id = id;
            Mappings = new List<ImportMappingModel>();

            foreach (var column in mappings)
            {
                Mappings.Add(new ImportMappingModel(column, existingFields.Where(x => x.Type == column.Type).Select(x => x.Name).ToList()));
            }
        }

        public IList<ImportMappingModel> Mappings { get; set; }
        public Guid Id { get; set; }
    }
}